package com.hex.ds.hdtp.core.inf.common.handler;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.hex.bigdata.hbda.utils.SecurityUtils;
import com.hex.ds.hdtp.core.inf.common.base.BaseUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * @author lwz
 * @date 2021-08-05
 * @des
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("crtTs", DateUtil.now(), metaObject);
        this.setFieldValByName("crtUser", BaseUtil.getNickName(), metaObject);
        this.setFieldValByName("crtUserName", BaseUtil.getUserId(), metaObject);

        this.setFieldValByName("upTs", DateUtil.now(), metaObject);
        this.setFieldValByName("upUser", BaseUtil.getNickName(), metaObject);
        this.setFieldValByName("upUserName", BaseUtil.getUserId(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("upTs", DateUtil.now(), metaObject);
        this.setFieldValByName("upUser", BaseUtil.getNickName(), metaObject);
        this.setFieldValByName("upUserName", BaseUtil.getUserId(), metaObject);
    }

}
